<%@ page language="java" import="javax.sql.*,javax.naming.*,java.sql.*" session="false"%>
<html>
<head>
<style type="text/css">
<!--
a { text-decoration: none }
body { font-family: verdana, helvetica, sans serif; font-size: 10pt; }
-->
</style>
</head>
<body>
<center>
<h3>This is a test of a Tomcat-managed connection pool</h3>
</center>
<%
try {
String jdbcname = "jdbc/sqlserver";
String cmd = "select title, url from TomcatResources order by title";
Context ctx = new InitialContext();
Context envCtx = (Context)ctx.lookup("java:comp/env");
DataSource ds = (DataSource)envCtx.lookup(jdbcname);
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(cmd);
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
out.println("<table border=\"1\">");
out.println("<tr bgcolor=\"lightGrey\">");
for (int i = 1; i <= cols; i++) {
out.println("<td align=\"center\" width=\"200\"><b>" +
rsmd.getColumnName(i) + "</b></td>");
}
out.println("</tr>");
while (rs.next()) {
     out.println("<tr>");
     for (int i = 1; i <= cols; i++) {
               out.println("<td align=\"left\">" +
               rs.getString(i) + "</td>");
     }
     out.println("</tr>");
}
out.println("</table>");
conn.close();

} catch(Exception e) {
out.println("Error: " + e);
e.printStackTrace();
}
%>
</body>
</html>